package com.groupbuying.store.controller.forInternal;

import com.groupbuying.store.utils.R;
import com.groupbuying.store.connector.SysconfigFeign;
import com.groupbuying.store.controller.forManage.BaseController;
import com.groupbuying.store.domain.StoreAccountDO;
import com.groupbuying.store.service.StoreAccountService;
import com.groupbuying.store.service.forManage.StoreRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api("服务商员工管理")
@RequestMapping("/staff")
@RestController
public class StoreStaffController extends BaseController {
    @Autowired
	StoreAccountService storeAccountService;

    @Autowired
	StoreRoleService roleService;

	@Autowired
	SysconfigFeign sysconfigFeign;


	/**
	 * 分页获取员工
	 * @param params
	 * @return
	 */
    @GetMapping()
	@ApiOperation(value = "获取员工", notes = "获取员工接口")
	public R listByPage(@RequestParam Map<String, Object> params) {
		return storeAccountService.internal_getStaffListLike(params);
	}

	/**
	 * 获取未绑定收银台的员工
	 * @param params
	 * @return
	 */
	@GetMapping("/unBangding")
	@ApiOperation(value = "获取未绑定收银台的员工", notes = "获取未绑定收银台的员工")
	public R getUnBangDing(@RequestParam Map<String, Object> params) {
		return storeAccountService.internal_getStaffList_unBangDing(params);
	}

	/**
	 * 添加员工
	 * @param storeAccountDO
	 * @author zmlmagic
	 * @return
	 */
	@PostMapping()
	@ApiOperation(value = "添加员工", notes = "新增员工接口")
	public R save(@RequestBody StoreAccountDO storeAccountDO) {
		return storeAccountService.internal_saveStaff(storeAccountDO);
	}

	/**
	 * 修改员工信息
	 * @param user
	 * @return
	 */
	@PostMapping("/changeInfo")
	@ApiOperation(value = "修改员工信息", notes = "修改员工信息")
	public R update(@RequestBody StoreAccountDO user) {
		return R.operate(storeAccountService.update(user) > 0);
	}


	/**
	 * 删除用户
	 * @param id
	 * @return
	 */
	@DeleteMapping()
	public R remove( String id) {
		return R.operate (storeAccountService.remove(id) > 0);
	}

	@PostMapping("/batchRemove")
	@ResponseBody
	public R batchRemove(@RequestParam("ids[]") String[] userIds) {
		int r = storeAccountService.batchRemove(userIds);
		if (r > 0) {
			return R.ok();
		}
		return R.error();
	}

	@PostMapping("/exits")
	@ResponseBody
	public boolean exits(@RequestParam Map<String, Object> params) {
		// 存在，不通过，false
		return !storeAccountService.exits(params);
	}

}
